package com.da.javatest.niuke.jianzhi;

import com.da.javatest.niuke.common.ListNode;

/**
 * @author chenlida
 * @date 2020/10/21 17:05
 * https://www.nowcoder.com/practice/d8b6b4358f774294a89de2a6ac4d9337?
 * tpId=13&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 *
 */
public class C16Solution {
    public static ListNode Merge(ListNode list1, ListNode list2) {
        ListNode head = new ListNode(-1);
        ListNode node = head;
        while (list1 != null && list2 != null) {
            if (list1.val >= list2.val) {
                node.next = list2;
                list2 = list2.next;
            } else {
                node.next = list1;
                list1 = list1.next;
            }
            node = node.next;
        }
        if (list1 == null) {
            node.next = list2;
        } else {
            node.next = list1;
        }
        return head.next;
    }

    public static void main(String[] args) {
        ListNode l1 = new ListNode(1);
        ListNode l2 = new ListNode(2);
        ListNode l3 = new ListNode(3);
        ListNode l4 = new ListNode(4);
        ListNode l5 = new ListNode(5);
        ListNode l6 = new ListNode(6);
        l1.next = l3;
        l3.next = l5;
        l2.next = l4;
        l4.next = l6;
        Merge(l1, l2);
    }

}
